package org.jeecg.modules.demo.chen.controller;


import org.jeecg.modules.demo.chen.entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
public class DemoController {
    @Autowired
    private org.jeecg.modules.demo.chen.service.ListService ListService;

    @GetMapping(value = "/update/{id}",produces = "application/json; charset=utf-8")
    public String update(@PathVariable Integer id, HttpServletResponse resp)throws Exception{

            if (id == ListService.findID(id)) {
                Integer lists = ListService.findListQuantity(id);
                System.out.println(lists);
                ListService.updateLists(id, lists);
                return "执行成功";
            } else {
                return "没有这个id";
            }
    }

    @GetMapping(value = "/findAllList",produces = "application/json; charset=utf-8")
    public CommonResult List(){
        List<SaleList> saleLists = ListService.findAllList();
        if (saleLists != null){
            return new CommonResult(200,"品牌销售榜单的信息是：",saleLists);
        }
        return new CommonResult(404,"没有查询到");
    }
    @GetMapping(value = "/findAllAnalysis",produces = "application/json; charset=utf-8")
    public CommonResult Analysis(){
        //查询所有售出鞋子的数量
        Integer quantity =  ListService.findAnalysisQuantity();
        //更新销售数量
        ListService.updateAnalysis(quantity);
        List<Analysis> analysisList = ListService.findAllAnalysis();
        if (analysisList != null){
            return new CommonResult(200,"销售分析的数据：",analysisList);
        }
        return new CommonResult(404,"没有查询到");
    }
    @GetMapping(value = "/findAllSummary",produces = "application/json; charset=utf-8")
    public CommonResult Summary(){
        //查询所有售出鞋子的数量
        Integer quantity =  ListService.findAllQuantity();
        //更新年销售数量
        ListService.updateSummary(quantity);
        List<Summary> summaryList = ListService.findAllSummary();
        if (summaryList != null){
            return new CommonResult(200,"销售年月周日的数据：",summaryList);
        }
        return new CommonResult(404,"没有查询到");
    }
    @GetMapping(value = "/findAllTarget",produces = "application/json; charset=utf-8")
    public CommonResult Target(){
        List<Target> targetList = ListService.findAllTarget();
        if (targetList != null){
            return new CommonResult(200,"销售目标的数据：",targetList);
        }
        return new CommonResult(404,"没有查询到");
    }

}
